package com.rongc.client.freight.business.waybill.view.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.rongc.client.freight.R;
import com.rongc.client.freight.base.BaseActivity;
import com.rongc.client.freight.business.waybill.view.fragment.WaybillFragment;
import com.viewpagerindicator.TabPageIndicator;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

/**
 * Created by ccqx on 2017/8/20.
 */

public class WaybillListMainActivity extends BaseActivity {
    private static final String[] CONTENT = new String[] { "进行中", "所有的"};

    @Bind(R.id.pager)
    ViewPager pager;
    @Bind(R.id.indicator)
    TabPageIndicator indicator ;

    FragmentPagerAdapter adapter;
    WaybillFragment mYJSFragment;
    WaybillFragment mWJSFragment;
    List<Fragment> mFragments = new ArrayList<Fragment>();


    @Override
    public void initView() {
        initToolbar(R.string.supply_waybilllist_title);

        if(mFragments != null && mFragments.size() == 0){
            mYJSFragment = WaybillFragment.getInstance("1");
            mWJSFragment = WaybillFragment.getInstance("");
            mFragments.add(mYJSFragment);
            mFragments.add(mWJSFragment);
        }

        adapter = new GoogleMusicAdapter(getSupportFragmentManager());

        pager.setAdapter(adapter);
        pager.setOffscreenPageLimit(2);

        indicator.setVisibility(View.VISIBLE);
        indicator.setViewPager(pager);


    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_waybill_list;
    }

    class GoogleMusicAdapter extends FragmentPagerAdapter {
        public GoogleMusicAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            switch (position) {
                case 0:
                    if(mYJSFragment == null)
                        mYJSFragment = WaybillFragment.getInstance("1");
                    return mYJSFragment;
                case 1:
                    if(mWJSFragment == null) {
                        mWJSFragment = WaybillFragment.getInstance("");
                    }
                    return mWJSFragment;
                default:
                    break;
            }

            return mFragments.get(position);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return CONTENT[position % CONTENT.length].toUpperCase();
        }

        @Override
        public int getCount() {
            return CONTENT.length;
        }

        /*@Override
        public int getItemPosition(Object object) {
            return PagerAdapter.POSITION_NONE;
        }*/
    }
}
